<template>
  <div class="login">
    <van-form class="dl">
      <van-field
        v-model="userform.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="userform.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" @click="login()">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      userform: {
        username: "",
        password: "",
      },
      userinfo: [
        { username: "admin", password: "123456" },
        { username: "root", password: "123456" },
        { username: "lg", password: "123456" },
      ],
    };
  },
  methods: {
    login() {
      let { username, password } = this.userform;
      let res = this.userinfo.some((v, k) => {
        return username == v.username && password == v.password;
      });
      if (res) {
        sessionStorage.setItem("userInfo", JSON.stringify(this.userform));
        // JSON.stringify.sessionStorage(userInfo);
        Toast("登陆成功");
        this.$router.push("/tab/my");
      } else {
        Toast("登陆失败");
      }
      // console.log(this.userInfo);
    },
  },
};
</script>

<style>
.dl {
  margin-top: 300px;
}
</style>